package cn.net.cfss.fgbp.provider.manage.utils;

import org.apache.commons.lang.StringUtils;

import javax.validation.constraints.NotBlank;
import java.text.SimpleDateFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author wutao
 * @version 1.0
 * @date 2021/3/10 16:55
 */
public class FormatUtils {

    /**
     * 校验租户的工作日期格式格式
     * @param workTime
     * @return
     */
    public static Boolean checkFormatTenantWorkTime(String workTime) {
        if (StringUtils.isBlank(workTime)) {
            return true;
        }

        String splitChar = ",";
        String[] split = workTime.split(splitChar);

        //格式校验HH:mm-HH:mm
        String path = "([01]?[0-9]|2[0-3]):[0-5][0-9]-([01]?[0-9]|2[0-3]):[0-5][0-9]";
        Pattern p= Pattern.compile(path);
        for (String s : split) {
            Matcher m = p.matcher(s);
            if (!m.matches()) {
                return false;
            }

            //如果符合HH:mm-HH:mm，判断后面的时间比前面那个时间更大
            String[] times = s.split("-");
            if (times[0].compareTo(times[1]) > 0) {
                return false;
            }
        }
        return true;
    }


}
